﻿using GCC.Container.Abstracts;

namespace Z.Test.JobDemo
{
    public class JobDemo2 : AbsJobBase
    {
        public JobDemo2(AbsGCCLogger logger) : base(logger)
        {
            Name = "我是测试job2,每秒输出一次时间";
            Interval = new TimeSpan(0, 0, 1);
        }

        public override Task Start(AbsGCCContext context)
        {
            return Task.Run(() =>
            {
                Console.WriteLine($" 我是JOB:{Name}  JOBID:{ID} 本次的EVENTID:{context.EventID} 当前时间:{DateTime.Now}");

            }, _cancellToken.Token);
        }

        protected override void Dispose(bool flag)
        {
            Console.WriteLine($" 我是JOB:{Name} 我被销毁了.");
            base.Dispose(flag);
        }
        public override Task Stop()
        {
            return Task.Run(() =>
            {
                Logger.Information($"Job {Name} stoping.");
                _cancellToken.Cancel();
                Logger.Information($"Job {Name} stoped.");
            });
        }
    }
}